package com.shujia.zookeeper;

import org.apache.zookeeper.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

public class Code06DeleteNode {
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {

        int sessionTimeout = 5 * 1000;
        ZooKeeper zkCli = new ZooKeeper("master:2181,node1:2181,node2:2181", sessionTimeout, new Watcher() {
            // 处理监视结果
            @Override
            public void process(WatchedEvent event) {
                System.out.println("监视器被打开... 正在连接...");
            }
        });

        // -1 表示删除最新版本
        zkCli.delete("/api",-1);
        List<String> children = zkCli.getChildren("/",false);
        for (String child : children) {
            System.out.println(child);
        }

        zkCli.close();

        // 作业：创建一个迭代删除的程序
    }
}
